package com.nibian.nibian.fragment;

import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nibian.nibian.R;
import com.nibian.nibian.activity.MainActivity;
import com.nibian.nibian.bean.TextBean;
import com.nibian.nibian.ui.ProgressDialogs;
import com.nibian.nibian.utils.SharedPreferenceTools;
import com.nibian.nibian.utils.UiUtils;
import com.nibianplus.base.BaseFragment;
import com.nibianplus.base.BaseObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

/**
 * @创建者 luck
 * @创建时间 ${DATA} 16:14
 * @描述 ${第三种风格主题}
 * @更新者 $Author$
 * @更新时间 $Date$
 * @更新描述 ${TODO}
 */
public class ThirdStyleFragment extends BaseFragment {

    public static final String sWORK_DAI_JI = "00";        // 待机
    public static final String sWORK_SHI_DIAN = "01";      // 市电
    public static final String sWORK_NI_BIAN = "02";       // 逆变
    public static final String sWORK_WRONG = "03";         // 故障
    public static final String sWORK_SHENG_DIAN = "04";    // 省电

    @BindView(R.id.btn_radiogroup)
    RadioGroup mBtn_radiogroup;                   //RadionGroup
    @BindView(R.id.rb_jiankong)
    RadioButton mRb_jiankong;                     //实时监控
    @BindView(R.id.rb_shuju)
    RadioButton mRrb_shuju;                       //历史数据
    @BindView(R.id.rb_shezhi)
    RadioButton mBb_shezhi;                       //参数设置
    @BindView(R.id.rb_shebei)
    RadioButton mRb_shebei;                       //设备信息
    @BindView(R.id.big_rl)
    RelativeLayout big_rl;                        //底部radioButton

    @BindView(R.id.tv_mode)
    TextView tv_mode;

    @BindView(R.id.third_openc)
    ImageView third_openc;                          //开关
    @BindView(R.id.ll_style_1)
    LinearLayout ll_style_1;                      //第一行4个显示
    @BindView(R.id.one_rl_iv)
    ImageView one_rl_iv;
    @BindView(R.id.one_rl_tv1_1)
    TextView one_rl_tv1_1;
    @BindView(R.id.one_rl_tv1_2)
    TextView one_rl_tv1_2;
    @BindView(R.id.two_rl_iv)
    ImageView two_rl_iv;
    @BindView(R.id.two_rl_tv1_1)
    TextView two_rl_tv1_1;
    @BindView(R.id.two_rl_tv1_2)
    TextView two_rl_tv1_2;
    @BindView(R.id.three_rl_iv)
    ImageView three_rl_iv;
    @BindView(R.id.three_rl_tv1_1)
    TextView three_rl_tv1_1;
    @BindView(R.id.three_rl_tv1_2)
    TextView three_rl_tv1_2;
    @BindView(R.id.four_rl_iv)
    ImageView four_rl_iv;
    @BindView(R.id.four_rl_tv1_1)
    TextView four_rl_tv1_1;
    @BindView(R.id.four_rl_tv1_2)
    TextView four_rl_tv1_2;
    @BindView(R.id.ll_style_2)                   //第二行三个显示
            LinearLayout ll_style_2;
    @BindView(R.id.ones_rl_iv)
    ImageView ones_rl_iv;
    @BindView(R.id.ones_rl_tv1_1)
    TextView ones_rl_tv1_1;
    @BindView(R.id.ones_rl_tv1_2)
    TextView ones_rl_tv1_2;
    @BindView(R.id.twos_rl_iv)
    ImageView twos_rl_iv;
    @BindView(R.id.twos_rl_tv1_1)
    TextView twos_rl_tv1_1;
    @BindView(R.id.twos_rl_tv1_2)
    TextView twos_rl_tv1_2;
    @BindView(R.id.threes_rl_iv)
    ImageView threes_rl_iv;
    @BindView(R.id.threes_rl_tv1_1)
    TextView threes_rl_tv1_1;
    @BindView(R.id.threes_rl_tv1_2)
    TextView threes_rl_tv1_2;
    @BindView(R.id.rl_ones)                     //三个圆的点击init
            RelativeLayout rl_ones;
    @BindView(R.id.rl_twos)
    RelativeLayout rl_twos;
    @BindView(R.id.rl_threes)
    RelativeLayout rl_threes;
    @BindView(R.id.iv_show1)                    //指示器
            ImageView iv_show1;
    @BindView(R.id.iv_show2)
    ImageView iv_show2;
    @BindView(R.id.iv_show3)
    ImageView iv_show3;
    @BindView(R.id.rl_ones_iv)
    ImageView rl_ones_iv;
    @BindView(R.id.rl_ones_tv)
    TextView rl_ones_tv;                        //光伏控制
    @BindView(R.id.rl_twos_iv)
    ImageView rl_twos_iv;
    @BindView(R.id.rl_twos_tv)
    TextView rl_twos_tv;                        //逆变系统
    @BindView(R.id.rl_threes_iv)
    ImageView rl_threes_iv;
    @BindView(R.id.rl_threes_tv)
    TextView rl_threes_tv;                      //储能电源
    @BindView(R.id.iv_msg1)                     //逆变器指示灯
            ImageView iv_msg1;
    @BindView(R.id.iv_msg2)
    ImageView iv_msg2;
    @BindView(R.id.iv_msg3)
    ImageView iv_msg3;
    @BindView(R.id.iv_msg4)
    ImageView iv_msg4;
    @BindView(R.id.iv_msg5)
    ImageView iv_msg5;
    private MainActivity mMMainActivity;
    private int mStyle;
    private Dialog loading;                   //加载框
    private boolean isOff = true;                   //默认是off
    private String mLanguages_key;
    public static ThirdStyleFragment sThirdStyleFragment;

    public static ThirdStyleFragment getInstance() {
        return sThirdStyleFragment;
    }

    private List<String> mListASCII = new ArrayList<>();                         //用来保存ascii码数据
    private List<String> mList_Show = new ArrayList<>();                         //用来保存ascii码数据
    private List<String> mList_show = new ArrayList<>();                         //用来保存ascii码数据

    /**
     * init - ui
     *
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        sThirdStyleFragment = this;
        mLanguages_key = SharedPreferenceTools.getString(UiUtils.getContext(), "LANGUAGES_KEY", "zh");
        if (mLanguages_key.equals("zh")) {
            loading = ProgressDialogs.getLoading(getActivity(), "正在加载...");
        } else {
            loading = ProgressDialogs.getLoading(getActivity(), "loading...");
        }
        loading.show();
        View inflate = View.inflate(UiUtils.getContext(), R.layout.third_style, null);
        ButterKnife.bind(this, inflate);
        mBtn_radiogroup.check(R.id.rb_jiankong);                                                    //在这里进行默认的第一个的选择底部
        mRb_jiankong.setTextColor(getResources().getColor(R.color.color_text_selected));
        getMainActivity();
        setFirstData();
        return inflate;
    }

    /**
     * init - loadData
     */
    private void setFirstData() {
        setInitBackgroundPhoto();
        rl_twos_iv.setBackgroundResource(R.mipmap.nibianxitongstyle22);
        rl_twos_tv.setTextColor(Color.parseColor("#ffffff"));
        iv_show2.setBackgroundResource(R.mipmap.jingbaostyle22);
        rl_twos.setBackgroundResource(R.mipmap.style23yuan2);
        ll_style_2.setVisibility(View.GONE);
        ll_style_1.setVisibility(View.VISIBLE);
        one_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
        one_rl_tv1_1.setText("--V");
        two_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
        two_rl_tv1_1.setText("--V");
        three_rl_iv.setBackgroundResource(R.mipmap.pinlvstyle2);
        three_rl_tv1_1.setText("--Hz");
        four_rl_iv.setBackgroundResource(R.mipmap.gonglvstyle2);
        four_rl_tv1_1.setText("--W");
        if (mLanguages_key.equals("zh")) {                                                           //显示中文
            one_rl_tv1_2.setText("输入电压");
            two_rl_tv1_2.setText("输出电压");
            three_rl_tv1_2.setText("输出频率");
            four_rl_tv1_2.setText("负载功率");
        } else {                                                                                      //显示英文
            one_rl_tv1_2.setText("Input volt");
            two_rl_tv1_2.setText("Output volt");
            three_rl_tv1_2.setText("Output freq");
            four_rl_tv1_2.setText("Load power");
        }

//        if (TextUtils.equals(one_rl_tv1_1.getText(), "--V")) {
//            if (mLanguages_key.equals("zh")) {                                                           //显示中文
//                tv_mode.setText("逆变");
//            } else {                                                                                      //显示英文
//                tv_mode.setText("Inverter");
//            }
//        } else {
//            if (mLanguages_key.equals("zh")) {                                                           //显示中文
//                tv_mode.setText("市电");
//            } else {                                                                                      //显示英文
//                tv_mode.setText("Gird");
//            }
//        }
//
//        if (TextUtils.equals(one_rl_tv1_1.getText(), "000.0V")) {
//            if (mLanguages_key.equals("zh")) {                                                           //显示中文
//                tv_mode.setText("逆变");
//            } else {                                                                                      //显示英文
//                tv_mode.setText("Inverter");
//            }
//        }
    }

    /**
     * 获取MainActivity实例
     */
    private void getMainActivity() {
        mMMainActivity = (MainActivity) getActivity();
    }

    /**
     * 事件处理
     *
     * @param v
     */
    @OnClick({R.id.rb_jiankong, R.id.rb_shuju, R.id.rb_shezhi, R.id.rb_shebei, R.id.rl_ones, R.id.rl_twos, R.id.rl_threes, R.id.third_openc})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rb_jiankong:                                                                  //实时监控 - 不必处理
                break;
            case R.id.rb_shuju:                                                                     //历史数据
                mMMainActivity.changeFragment(1);
                setTextColor();
                mMMainActivity.setColorChoose(1);
                mMMainActivity.showJianKongFra();
                break;
            case R.id.rb_shezhi:                                                                    //参数设置
                mMMainActivity.changeFragment(2);
                setTextColor();
                mMMainActivity.setColorChoose(2);
                mMMainActivity.showJianKongFra();
                break;
            case R.id.rb_shebei:                                                                    //设备信息
                mMMainActivity.changeFragment(3);
                setTextColor();
                mMMainActivity.setColorChoose(3);
                mMMainActivity.showJianKongFra();
                break;
            case R.id.third_openc:                                                                  //开关
                if (isOff == true) {
                    third_openc.setBackgroundResource(R.mipmap.styleon);
                    isOff = false;
                } else {
                    third_openc.setBackgroundResource(R.mipmap.styleoff);
                    isOff = true;
                }
                break;
            case R.id.rl_twos:                                                                      //逆变系统 - 对应4个显示
                EventBus.getDefault().post("sendNiBianXiTong");
                setInitBackgroundPhoto();
                rl_twos_iv.setBackgroundResource(R.mipmap.nibianxitongstyle22);
                rl_twos_tv.setTextColor(Color.parseColor("#ffffff"));
                iv_show2.setBackgroundResource(R.mipmap.jingbaostyle22);
                rl_twos.setBackgroundResource(R.mipmap.style23yuan2);
                ll_style_2.setVisibility(View.GONE);
                ll_style_1.setVisibility(View.VISIBLE);
                one_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
                one_rl_tv1_1.setText("--V");
                two_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
                two_rl_tv1_1.setText("--V");
                three_rl_iv.setBackgroundResource(R.mipmap.pinlvstyle2);
                three_rl_tv1_1.setText("--Hz");
                four_rl_iv.setBackgroundResource(R.mipmap.gonglvstyle2);
                four_rl_tv1_1.setText("--W");
                if (mLanguages_key.equals("zh")) {
                    one_rl_tv1_2.setText("输入电压");
                    two_rl_tv1_2.setText("输出电压");
                    three_rl_tv1_2.setText("输出频率");
                    four_rl_tv1_2.setText("负载功率");
                } else {
                    one_rl_tv1_2.setText("Input volt");
                    two_rl_tv1_2.setText("Output volt");
                    three_rl_tv1_2.setText("Output freq");
                    four_rl_tv1_2.setText("Load power");
                }
                break;
            case R.id.rl_threes:                                                                    //储能电源
//                mMMainActivity.sendChuNengDianYuan();
                EventBus.getDefault().post("sendChuNengDianYuan");

                setInitBackgroundPhoto();
                rl_threes_iv.setBackgroundResource(R.mipmap.chunengdianyuanstyle22);
                rl_threes_tv.setTextColor(Color.parseColor("#ffffff"));

                iv_show3.setBackgroundResource(R.mipmap.jingbaostyle22);
                rl_threes.setBackgroundResource(R.mipmap.style23yuan2);
                ll_style_1.setVisibility(View.GONE);
                ll_style_2.setVisibility(View.VISIBLE);
                ones_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
                ones_rl_tv1_1.setText("--V");
                twos_rl_iv.setBackgroundResource(R.mipmap.dianliangstyle2);
                twos_rl_tv1_1.setText("--%");
                threes_rl_iv.setBackgroundResource(R.mipmap.wendusstyle2);
                threes_rl_tv1_1.setText("--℃");

                if (mLanguages_key.equals("zh")) {
                    ones_rl_tv1_2.setText("电压");
                    twos_rl_tv1_2.setText("电量");
                    threes_rl_tv1_2.setText("温度");
                } else {
                    ones_rl_tv1_2.setText("Volt");
                    twos_rl_tv1_2.setText("Electricity");
                    threes_rl_tv1_2.setText("Temp");
                }
                break;
            case R.id.rl_ones:                                                                      //光伏控制
//                mMMainActivity.sendGuangFuKongZhi();
                EventBus.getDefault().post("sendGuangFuKongZhi");

                setInitBackgroundPhoto();
                rl_ones_iv.setBackgroundResource(R.mipmap.guangfukongzhistyle22);
                rl_ones_tv.setTextColor(Color.parseColor("#ffffff"));

                iv_show1.setBackgroundResource(R.mipmap.jingbaostyle22);
                rl_ones.setBackgroundResource(R.mipmap.style23yuan2);
                ll_style_1.setVisibility(View.GONE);
                ll_style_2.setVisibility(View.VISIBLE);
                ones_rl_iv.setBackgroundResource(R.mipmap.dianyastyle2);
                ones_rl_tv1_1.setText("--V");
                twos_rl_iv.setBackgroundResource(R.mipmap.dianliustyle2);
                twos_rl_tv1_1.setText("--A");
                threes_rl_iv.setBackgroundResource(R.mipmap.gonglvstyle2);
                threes_rl_tv1_1.setText("--W");

                if (mLanguages_key.equals("zh")) {
                    ones_rl_tv1_2.setText("电压");
                    twos_rl_tv1_2.setText("电流");
                    threes_rl_tv1_2.setText("功率");
                } else {
                    ones_rl_tv1_2.setText("Volt");
                    twos_rl_tv1_2.setText("Current");
                    threes_rl_tv1_2.setText("Power");
                }
                break;
        }
    }

    /**
     * init - 三个圆的点击默认
     */
    public void setInitBackgroundPhoto() {
        rl_ones.setBackgroundResource(R.mipmap.style23yuan1);
        rl_twos.setBackgroundResource(R.mipmap.style23yuan1);
        rl_threes.setBackgroundResource(R.mipmap.style23yuan1);

        iv_show1.setBackgroundResource(R.mipmap.jingbaostyle21);
        iv_show2.setBackgroundResource(R.mipmap.jingbaostyle21);
        iv_show3.setBackgroundResource(R.mipmap.jingbaostyle21);

        rl_ones_iv.setBackgroundResource(R.mipmap.guangfukongzhistyle21);
        rl_twos_iv.setBackgroundResource(R.mipmap.nibianxitongstyle21);
        rl_threes_iv.setBackgroundResource(R.mipmap.chunengdianyuanstyle21);
        rl_ones_tv.setTextColor(Color.parseColor("#777374"));
        rl_twos_tv.setTextColor(Color.parseColor("#777374"));
        rl_threes_tv.setTextColor(Color.parseColor("#777374"));
    }

    /**
     * 设置字体颜色F
     */
    public void setTextColor() {
        mRb_jiankong.setTextColor(getResources().getColor(R.color.bottom_tab_font_color));
        mRrb_shuju.setTextColor(getResources().getColor(R.color.bottom_tab_font_color));
        mBb_shezhi.setTextColor(getResources().getColor(R.color.bottom_tab_font_color));
        mRb_shebei.setTextColor(getResources().getColor(R.color.bottom_tab_font_color));
        mRb_jiankong.setChecked(true);                                                              //在这里进行默认的第一个的选择底部
    }

    /**
     * 串口传递的数据
     *
     * @param extra_data
     */
    public void setUiData(String extra_data) {
        UiUtils.toast(extra_data);
    }

    /**
     * 设置逆变器状态
     *
     * @param list
     */
    public void setNiBianStateData(List<String> list) {
        try {
            if (mListASCII != null) {
                mListASCII.clear();
                mList_Show.clear();
            }
            if (list != null && list.size() == 5) {
                String s1 = list.get(1);
                String s2 = list.get(2);
                String s3 = list.get(3);
                String s4 = list.get(4);
                String s = GetValue(s1 + s2 + s3 + s4);
                SystemClock.sleep(100);
                String nb_Data = s.replace("^[a]{4}[f]{4}[a-zA-Z0-9]{4}$", "");
                Log.d("nibiaqiData_state", nb_Data);
                //在进行截取 - 以20结束 - 并将数据转换为ASCII码值
                //283232392e3020 3232392e3020 3232362e3020 30303020 35302e302031332e 342030302e30203030303031303031020101cb030000000002000d
                String[] split = nb_Data.replace("20", ",").split(",");
                for (int i = 0; i < split.length; i++) {
                    String data = split[i].toString();
                    String s5 = UiUtils.convertHexToString(data);                                  //两位截取 - 并转换ascii码
                    Log.d("ascii", s5);
                    mListASCII.add(s5);
                }


                one_rl_tv1_1.setText(split(mListASCII.get(0), 1) + "V");                                        //输入电压
                two_rl_tv1_1.setText(split(mListASCII.get(2), 1) + "V");                                        //输出电压
                three_rl_tv1_1.setText(split(mListASCII.get(4), 1) + "Hz");                                     //输出频率
                four_rl_tv1_1.setText(split(mListASCII.get(3), 1) + "W");                                       //负载功率

                setShowData(nb_Data);

                String type = s.substring(s.length() - 20, s.length() - 18);

                if (TextUtils.equals(type, sWORK_NI_BIAN)) {
                    if (mLanguages_key.equals("zh")) {                                                           //显示中文
                        tv_mode.setText("逆变");
                    } else {                                                                                      //显示英文
                        tv_mode.setText("INV");
                    }
                } else if (TextUtils.equals(type, sWORK_SHI_DIAN)) {
                    if (mLanguages_key.equals("zh")) {                                                           //显示中文
                        tv_mode.setText("市电");
                    } else {                                                                                      //显示英文
                        tv_mode.setText("Line");
                    }
                } else if (TextUtils.equals(type, sWORK_SHENG_DIAN)) {
                    if (mLanguages_key.equals("zh")) {                                                           //显示中文
                        tv_mode.setText("省电");
                    } else {                                                                                      //显示英文
                        tv_mode.setText("Saver");
                    }
                } else if (TextUtils.equals(type, sWORK_DAI_JI)) {
                    if (mLanguages_key.equals("zh")) {                                                           //显示中文
                        tv_mode.setText("待机");
                    } else {                                                                                      //显示英文
                        tv_mode.setText("Standby");
                    }
                } else if (TextUtils.equals(type, sWORK_WRONG)) {
                    if (mLanguages_key.equals("zh")) {                                                           //显示中文
                        tv_mode.setText("故障");
                    } else {                                                                                      //显示英文
                        tv_mode.setText("Fault");
                    }
                }
            }
        } catch (Exception e) {
        }
        list.clear();
    }

    /**
     * 截取小数点后一位
     *
     * @param params
     * @param n
     * @return
     */
    private String split(String params, int n) {
        int index = n + 1;
        if (params != null && params.indexOf(".") != -1) {
            params = params.substring(0, params.indexOf(".") + index);
        }
        return params;
    }

    /**
     * 设置灯光的显示
     *
     * @param nb_Data
     */
    private void setShowData(String nb_Data) {
        // 3232392e30203232392e30203232362e30203030302035302e372031332e392030302e30203030303031303031020101cb04000000000200
        //倒数截取后六位  55-56-57
        String showData = nb_Data.substring(nb_Data.length() - 6, nb_Data.length());
        Log.d("nibiaqiData", showData);
        if (showData.substring(0, 2).equals("00")) {                                                  //则是报警状态 - 55位数据
            int i = UiUtils.toTen(showData.substring(0, 2));
            if (i == 1) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 2) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 3) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 4) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 6) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 8) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            } else if (i == 9) {
                iv_msg5.setBackgroundResource(R.mipmap.jinggaodengstyle22);
            }
        }

        //然后在截取56位 - 将其转换成二进制 - 在根据二进制进行判断即可
        String showOther = showData.substring(2, 4);                                                //其它的状态显示 - 56数据
        String s5 = UiUtils.convertHexToBinary(showOther);                                          //0000 0010
        Log.d("nibiaqiData", s5);
        char[] chars = s5.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            mList_Show.add(chars[i] + "");
        }
        if (mList_Show.get(0).equals("1") && mList_Show.get(1).equals("1")) {                       //欠压
            iv_msg3.setImageResource(R.mipmap.jinggaodengstyle22);
        } else {
            iv_msg3.setImageResource(R.mipmap.jinggaodengstyle21);
        }
        if (mList_Show.get(2).equals("1")) {                                                         //过压--5
            iv_msg4.setImageResource(R.mipmap.jinggaodengstyle22);
        } else {
            iv_msg4.setImageResource(R.mipmap.jinggaodengstyle21);
        }

        //然后在截取57位 - 将其转换成二进制 - 在根据二进制进行判断即可
        String s57 = showData.substring(4, 6);                                                //其它的状态显示 - 56数据
        String ss57 = UiUtils.convertHexToBinary(s57);
        char[] c57 = ss57.toCharArray();
        for (int i = 0; i < c57.length; i++) {
            mList_show.add(c57[i] + "");
        }
        if (mList_show.get(6).equals("1")) {                                                         //过温
            iv_msg1.setImageResource(R.mipmap.jinggaodengstyle22);
        } else {
            iv_msg1.setImageResource(R.mipmap.jinggaodengstyle21);
        }
        if (mList_show.get(1).equals("1") && mList_show.get(2).equals("1") && mList_show.get(3).equals("1")) {       //过载
            iv_msg2.setImageResource(R.mipmap.jinggaodengstyle22);
        } else {
            iv_msg2.setImageResource(R.mipmap.jinggaodengstyle21);
        }
    }

    /**
     * 截取28 - oD数据
     */
    public static String GetValue(String str) {
        String jieguo = null;
        try {
            jieguo = str.substring(str.indexOf("28") + 2, str.indexOf("0d"));
        } catch (Exception e) {
        } finally {
        }
        return jieguo;
    }

    /**
     * //     * diolog 取消
     */
    @Override
    public void onDestroy() {
        super.onDestroy();
        if (loading != null) {
            loading.cancel();
        }
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void refreshUI(BaseObject object, int what) {
    }

    @Override
    protected BaseObject createDataObject() {
        return TextBean.getInstance(getTagName());
    }

    public void setGuangFuData(String data) {
        try {
            // [ffff000c5452414e53504f52543d320daaaa,ffff020b 0103 06 0000 0000 0000 2175 aaaa]

            String substring2 = data.substring(14, 18);                                           //光伏控制 - 电压
            Log.d("tag", substring2);
            int i1 = UiUtils.toTen(substring2);
            String dy = String.format("%.1f", i1 * 0.1);
            ones_rl_tv1_1.setText(dy + "V");

            String substring3 = data.substring(18, 22);
            Log.d("tag", substring3);                                                            //电流
            int i2 = UiUtils.toTen(substring3);
            String dl = String.format("%.1f", i2 * 0.01);
            twos_rl_tv1_1.setText(dl + "A");

            String substring4 = data.substring(22, 26);
            Log.d("tag", substring4);
            threes_rl_tv1_1.setText(UiUtils.toTen(substring4) + "W");

        } catch (Exception e) {
        } finally {
        }

    }

    /**
     * 设置数据
     */
    public void setGuangFuData(List<String> list) {
        if (list != null && list.size() >= 1) {
            try {
                Log.d("mListData2", list + "");
                // [ffff000c5452414e53504f52543d320daaaa,ffff020b 0103 06 0000 0000 0000 2175 aaaa]

                String s1 = list.get(1);
                String substring2 = s1.substring(14, 18);                                           //光伏控制 - 电压
                Log.d("tag", substring2);
                int i1 = UiUtils.toTen(substring2);
                String dy = String.format("%.1f", i1 * 0.1);
                ones_rl_tv1_1.setText(dy + "V");

                String substring3 = s1.substring(18, 22);
                Log.d("tag", substring3);                                                            //电流
                int i2 = UiUtils.toTen(substring3);
                String dl = String.format("%.1f", i2 * 0.01);
                twos_rl_tv1_1.setText(dl + "A");

                String substring4 = s1.substring(22, 26);
                Log.d("tag", substring4);
//                int i3 = Integer.parseInt(dy) * 10;
//                int i4 = Integer.parseInt(dl) * 10;
//                String d2 = String.format("%.1f",i3* i4*0.1 );
                threes_rl_tv1_1.setText(UiUtils.toTen(substring4) + "W");

            } catch (Exception e) {
            } finally {
                list.clear();
            }
        }
    }

    public void setChuNengData(int dataCount, String data) {
        try {
            if (dataCount == 0) {
                //ffff 0207 0103 02 007a 39a7 aaaa
                String substring1 = data.substring(14, 18);
                String dy = String.format("%.1f", UiUtils.toTen(substring1) * 0.1);
                ones_rl_tv1_1.setText(dy + "V");
            } else if (dataCount == 1) {
                //ffff 0209 0103 04 004e 007a 1bc7 aaaa
                String substring2 = data.substring(14, 18);                                           //读蓄电池容量
                int dl = UiUtils.toTen(substring2);
                if (dl >= 100) {
                    dl = 100;
                }
                twos_rl_tv1_1.setText(dl + "%");
            } else if (dataCount == 2) {
                //ffff 0209 0103 04 0000 1419 34f9 aaaa
                //ffff 0209 0103 04 02bc 1f19 f395 aaaa
                //ffff 0209 0103 04 003d 1f19 a205 aaaa
                //ffff 0209 0103 04 0000 1c19 3339 aaaa
                String substring3 = data.substring(20, 22);                                           //读蓄电池容量
                Log.d("tag333", substring3);
                int wd = UiUtils.toTen(substring3);
                threes_rl_tv1_1.setText(wd + "℃");
            }
        } catch (Exception e) {
        }

    }

    /**
     * 储能电源数据
     */
    public void setChuNengData(List<String> list) {
        //[ffff000c5452414e53504f52543d320daaaa, ffff0207010302007a39a7aaaa, ffff0209010304 004e 007a 1bc7 aaaa, ffff0209010304 0000 1419 34f9aaaa]
        if (list != null && list.size() >= 4) {
            Log.d("mListData2", list + "");
            try {
                //ffff 0207 0103 02 007a 39a7 aaaa
                String s1 = list.get(1);                                                            //输入电压 电量温度
                String substring1 = s1.substring(14, 18);
                String dy = String.format("%.1f", UiUtils.toTen(substring1) * 0.1);
                ones_rl_tv1_1.setText(dy + "V");

                //ffff 0209 0103 04 004e 007a 1bc7 aaaa
                String s2 = list.get(2);
                String substring2 = s2.substring(14, 18);                                           //读蓄电池容量
                int dl = UiUtils.toTen(substring2);
                if (dl >= 100) {
                    dl = 100;
                }
                twos_rl_tv1_1.setText(dl + "%");

                //ffff 0209 0103 04 0000 1419 34f9 aaaa
                //ffff 0209 0103 04 02bc 1f19 f395 aaaa
                //ffff 0209 0103 04 003d 1f19 a205 aaaa
                String s3 = list.get(3);
                String substring3 = s3.substring(14, 18);                                           //读蓄电池容量
                Log.d("tag333", substring3);
                int wd = UiUtils.toTen(substring3);
                threes_rl_tv1_1.setText(wd + "℃");
            } catch (Exception e) {
            } finally {
                list.clear();
            }
        }
    }
}
